var coupon_content = document.getElementById("ui-view-12");   				          //优惠券内容
var no_ul = coupon_content.getElementsByClassName("vou-container bk-t-border")[0];    //不用优惠券
var no_ul_li = coupon_content.getElementsByTagName("li")[0];
var no_ul_span = no_ul.getElementsByTagName("span")[0];							      //不用优惠券的按钮
var use_ul = coupon_content.getElementsByClassName("vou-container mt5")[0];           //可用优惠券
var coupon_list = use_ul.getElementsByTagName("li");  				                  //可用优惠券列表   
var coupon_list_btn = [];          
var coupon_btn_span = [];                    
var discount_moneys = [];   
var discount_money =  [];   //优惠券的金额
var money_num = [];		

var coupon_text = coupon.getElementsByClassName("m-txt m-txt-space js_discount_info btn btn-block")[0];  //优惠券文字描述



//选择可用优惠券
	for(var i=0;i<coupon_list.length;i++){
		coupon_list_btn[i] = coupon_list[i].getElementsByClassName("vou-select")[0];      //优惠券按钮
		coupon_btn_span[i] = coupon_list_btn[i].getElementsByTagName("span")[0];          //选中按钮
		discount_moneys[i] = coupon_list[i].getElementsByClassName("vou-cards")[0];        
		discount_money[i] = discount_moneys[i].innerText;                                 //优惠券金额  含￥
		
        money_num[i] = parseInt(discount_money[i].replace(/[^0-9]/ig,"")); 

		coupon_list[i].index=i;
		//点击可用优惠券
		coupon_list[i].onclick=function(){    
			no_ul_span.setAttribute("class","vou-radio js_select_dot");
			for(var i=0;i<coupon_list.length;i++){
				coupon_btn_span[i].setAttribute("class","vou-radio js_select_dot");
			}
			coupon_btn_span[this.index].setAttribute("class","vou-radio js_select_dot current");
			coupon_text.innerHTML = "优惠" + discount_money[this.index];
			$("#js_paybar_wrap").find("p").eq(1).css("display","block");
			$("#js_paybar_wrap").find("p").eq(1).text("优惠已减"+discount_money[this.index]);

			paybar_price.innerHTML= final_money - money_num[this.index];   //相减
		}
		
		//点击不用优惠券
		no_ul_li.onclick=function(){
			for(var i=0;i<coupon_list.length;i++){
				coupon_btn_span[i].setAttribute("class","vou-radio js_select_dot");
			}
			no_ul_span.setAttribute("class","vou-radio js_select_dot current");
			
			coupon_text.innerHTML = "不使用";
			$("#js_paybar_wrap").find("p").eq(1).css("display","none");	
		}
	}
